package love.yuanmengrobot.als.system.dao.impl;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:CHJY创幻
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/6/9 20:52
 */

import love.yuanmengrobot.als.system.dao.MainPageContentDao;
import love.yuanmengrobot.als.system.javaBean.Alsannouncement;
import love.yuanmengrobot.als.utilPublic.JdbcUtil;
import love.yuanmengrobot.als.utilPublic.SqlString;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


public class MainPageContentDaoImpl implements MainPageContentDao {

    @Override
    public  List<Alsannouncement>  selectAllAnnouncement() {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        List<Alsannouncement> alsannouncementsList=new ArrayList<Alsannouncement>();
        Alsannouncement alsannouncement=null;
        try {

            conn = JdbcUtil.getConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(SqlString.selectAnnouncementSql());

            if(rs!=null){
                while (rs.next()) {
                    alsannouncement = new Alsannouncement();
                    alsannouncement.setNoticeID(rs.getString("NOTICE_ID"));
                    alsannouncement.setPublisher(rs.getString("PUBLISHER"));
                    alsannouncement.setTitile(rs.getString("TITLE"));
                    alsannouncement.setNotice_content(rs.getString("NOTICE_CONTENT"));
                    alsannouncement.setNotice_date(rs.getString("NOTICE_DATE"));
                    alsannouncementsList.add(alsannouncement);
                }
                return alsannouncementsList;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {//回收资源
            JdbcUtil.close(rs,stmt,conn);
        }
        return null;
    }
}
